
<link rel="stylesheet" href="../css/uploadify.css" type="text/css" />
<link rel="stylesheet" href="../css/body.css" type="text/css" />
<script type="text/javascript" src="../js/view.js"></script>

<script type="text/javascript">
arr= new Array();
function startUpload(id, conditional)
{
		$('#'+id).uploadifyUpload();
}
</script>

<script type="text/javascript">
	Ext.onReady(function(){
	$('#fileUploadname2').uploadify({
	  	'uploader'	: '../js/uploadify/uploadify.swf',
	  	'script'    : '../js/uploadify/uploadify.php',
	  	'multi'			: true,
	  	'height'		:	'25', //height of your browse button file
	  	'width'			:	'100', //width of your browse button file
	  	'simUploadLimit' : '3', //remove this to set no limit on simultaneous uploads
	    'buttonText' : 'Browser...',
	    'displayData': 'speed',
	  	'cancelImg' : '../js/uploadify/cancel.png',
		'folder'    : '../upload/collections', //folder to save uploads to
		'scriptData': {'name':'collection'},
		'fileExt'     : '*.jpg;*.gif;*.png;*.jpeg',
		'fileDesc'    : 'Image Files',
  		'onAllComplete'  : function() {
			view.add_image('image_collection');
    	},
		'onError': function(){
			alert("Quá trình upload bị lỗi");
			window.location.reload();
		}
	});
	view.add_image('image_collection');
	$("#btndel").click(function(){
		var ids= common.getChecked('image_collection[]');
		if(ids == ""){
			alert("Chưa chọn hình cần xóa");
		}else{
			if(confirm("Bạn chắc chắn muốn xóa?")){
				Ext.Ajax.request({
					url:  'services/delete_image.php',
					method: 'POST',
					params: {act :'image_collection',
						     ids : ids
						     },
					success: function ( result, request ) {	
						if (result.responseText == 1){
							alert("Xóa thành công");
								view.add_image('image_collection');
						}
					},
					failure: function ( result, request ) {
	    			}
				});
			}
		}
	});
	$('#btnedit').click(function(){
	var ids= common.getChecked('image_collection[]');
	if(ids ==""){
		alert("Chưa chọn nội dung cần thay đổi");
	}else{
		var list = document.getElementsByName('image_collection');
		$(list).attr('disabled',true);
		view.edit_click(ids);
	}
	});
	$('#btnupdate').click(function(){
		var ids= common.getChecked('image_collectionp[]');
		view.update_click('image_collection',ids);
	});
	
	$('#btncancel').click(function(){
		$("#btnupdate,#btnedit,#btncancel").toggle();
		$("#btndel,#btncheck,#btnuncheck").removeAttr('disabled');
		var list = document.getElementsByName('image_collection');
		$(list).removeAttr('disabled');
		var ids = common.getChecked('image_collection');
		list_id = ids.split(",");
		for(var i=0 ; i< list_id.length;i++){
			$('#tb_' + list_id[i]).attr('disabled',true);
			$('#tb_' + list_id[i]).css('border','');
		}
		common.setUnCheckAll('image_collection[]');
		if($('#btnuncheck').css('display') != 'none'){
			$('#btncheck,#btnuncheck').toggle();
		}
	});
	$('#btncheck').click(function(){
		common.setCheckAll('image_collection[]');
		$('#btncheck,#btnuncheck').toggle();
	});
	$('#btnuncheck').click(function(){
		common.setUnCheckAll('image_collection[]');
		$('#btncheck,#btnuncheck').toggle();
	});
		
});
</script>

<h2>COLLECTIONS PAGE</h2>
	

<div id="uploadform">
	<hr width=100% size="1" color="" align="center">
		<h2>Upload Images</h2>
		<p>Hiển thị chức năng thêm hình ảnh vào album. Có thể chọn nhiều file</p>
		<div id="fileUploadname2">You have a problem with your javascript</div>
		<a href="javascript:startUpload('fileUploadname2')">Start Upload</a> |  <a href="javascript:$('#fileUploadname2').uploadifyClearQueue()">Clear Queue</a>
    	<p></p>
	<hr width=100% size="1" color="" align="center">

</div>
<div id="img_cm">
	<fieldset>
		<legend>Form Collections</legend>	
	<div id="btn_del" >
		<input id="btndel" type="button" value="DELETE" />
		<input id="btncheck" type="button" value="CHECK" />
		<input id="btnuncheck" type="button" value="UNCHECK" style="display:none"/>
		<input id="btnedit" type="button" value="EDIT" />
		<input id="btnupdate" type="button" value="UPDATE" style="display:none" />
		<input id="btncancel" type="button" value="CANCEL" style="display:none" />
	</div>	
	<div id="image">
	</div>
	</fieldset>
</div>
